import init.InitConf;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import com.datastream.process.InfluxProcess;

import java.util.Arrays;
import java.util.Properties;

/**
 * Created by kzdatd on 2020/1/14.
 */
public class InfluxConsumer {

    private static InfluxProcess influxProcess;
    public static void main(String[] args) {
        InitConf initConf = new InitConf();
        initConf.init();
        influxProcess = new InfluxProcess(InitConf.kmxServerConfig);
        Properties props = new Properties();
        props.setProperty("bootstrap.servers", "192.168.130.70:9092");
        props.setProperty("group.id", "test");
        props.setProperty("enable.auto.commit", "true");
        props.setProperty("auto.commit.interval.ms", "1000");
        props.setProperty("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        props.setProperty("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
        consumer.subscribe(Arrays.asList("outputtopic"));
        while (true) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            for (ConsumerRecord<String, String> record : records){
                System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
                influxProcess.writerInflux(record);
            }
        }
    }
}
